home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / ProgressBar.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  5.5 KB  |  294 lines

  1. package symantec.itools.awt.util;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Rectangle;
  10. import symantec.itools.awt.AlignStyle;
  11. import symantec.itools.awt.BevelStyle;
  12.  
  13. public class ProgressBar extends Canvas implements BevelStyle, AlignStyle {
  14.    public static final int INDENT_ZERO = 0;
  15.    public static final int INDENT_ONE = 1;
  16.    public static final int INDENT_TWO = 2;
  17.    private int align;
  18.    private int type;
  19.    private int progress;
  20.    private Color color1;
  21.    private Color color2;
  22.    private Color textColor;
  23.    private Color borderedColor;
  24.    private Color progressColor;
  25.    private boolean bShowProgress;
  26.    private boolean bDrawBoxes;
  27.    private int boxWidth;
  28.    private int gapWidth;
  29.    // $FF: renamed from: fm java.awt.FontMetrics
  30.    private FontMetrics field_0;
  31.    private int xTemp;
  32.    private int yTemp;
  33.    private int indent;
  34.  
  35.    public ProgressBar() {
  36.       this(1, 3, 0);
  37.    }
  38.  
  39.    public ProgressBar(int var1, int var2, int var3) {
  40.       this.bShowProgress = true;
  41.       this.bDrawBoxes = false;
  42.       this.boxWidth = 10;
  43.       this.gapWidth = 2;
  44.       this.textColor = Color.black;
  45.       this.borderedColor = Color.black;
  46.       this.progressColor = Color.blue;
  47.       this.setBorderIndent(var3, false);
  48.       this.setBevelStyle(var2);
  49.       this.setAlignStyle(var1);
  50.    }
  51.  
  52.    public void setProgressBarColor(Color var1) {
  53.       this.progressColor = var1;
  54.       ((Component)this).invalidate();
  55.    }
  56.  
  57.    public Color getProgressBarColor() {
  58.       return this.progressColor;
  59.    }
  60.  
  61.    public void setProgressBarTextColor(Color var1) {
  62.       this.textColor = var1;
  63.       ((Component)this).invalidate();
  64.    }
  65.  
  66.    public Color getProgressBarTextColor() {
  67.       return this.textColor;
  68.    }
  69.  
  70.    public boolean getDrawBoxes() {
  71.       return this.bDrawBoxes;
  72.    }
  73.  
  74.    public void setDrawBoxes(boolean var1) {
  75.       this.bDrawBoxes = var1;
  76.       ((Component)this).invalidate();
  77.    }
  78.  
  79.    public void setBoxWidth(int var1) {
  80.       this.boxWidth = var1;
  81.       ((Component)this).invalidate();
  82.    }
  83.  
  84.    public int getBoxWidth() {
  85.       return this.boxWidth;
  86.    }
  87.  
  88.    public void setGapWidth(int var1) {
  89.       this.gapWidth = var1;
  90.       ((Component)this).invalidate();
  91.    }
  92.  
  93.    public int getGapWidth() {
  94.       return this.gapWidth;
  95.    }
  96.  
  97.    public boolean getShowProgress() {
  98.       return this.bShowProgress;
  99.    }
  100.  
  101.    public void setShowProgress(boolean var1) {
  102.       this.bShowProgress = var1;
  103.       ((Component)this).invalidate();
  104.    }
  105.  
  106.    public void setAlignStyle(int var1) {
  107.       this.align = var1;
  108.       ((Component)this).invalidate();
  109.    }
  110.  
  111.    public int getAlignStyle() {
  112.       return this.align;
  113.    }
  114.  
  115.    public void setBevelStyle(int var1) {
  116.       this.type = var1;
  117.       switch (this.type) {
  118.          case 0:
  119.             this.color1 = Color.black;
  120.             this.color2 = Color.white;
  121.             break;
  122.          case 1:
  123.             this.color1 = Color.white;
  124.             this.color2 = Color.black;
  125.             break;
  126.          case 2:
  127.             this.color1 = this.borderedColor;
  128.             this.color2 = this.borderedColor;
  129.             break;
  130.          default:
  131.             this.color1 = this.color2 = null;
  132.       }
  133.  
  134.       ((Component)this).invalidate();
  135.    }
  136.  
  137.    public int getBevelStyle() {
  138.       return this.type;
  139.    }
  140.  
  141.    public void setBorderIndent(int var1) {
  142.       this.setBorderIndent(var1, true);
  143.    }
  144.  
  145.    private void setBorderIndent(int var1, boolean var2) {
  146.       if (var1 < 0) {
  147.          this.indent = 0;
  148.       } else if (var1 > 2) {
  149.          this.indent = 2;
  150.       } else {
  151.          this.indent = var1;
  152.       }
  153.  
  154.       if (var2) {
  155.          ((Component)this).repaint();
  156.       }
  157.  
  158.    }
  159.  
  160.    public int getBorderIndent() {
  161.       return this.indent;
  162.    }
  163.  
  164.    public void setBorderedColor(Color var1) {
  165.       this.borderedColor = var1;
  166.       if (this.type == 2) {
  167.          this.color1 = var1;
  168.          this.color2 = var1;
  169.       }
  170.  
  171.       ((Component)this).invalidate();
  172.    }
  173.  
  174.    public Color getBorderedColor() {
  175.       return this.borderedColor;
  176.    }
  177.  
  178.    public void updateProgress(int var1) {
  179.       if (var1 < 0) {
  180.          var1 = 0;
  181.       }
  182.  
  183.       if (var1 > 100) {
  184.          var1 = 100;
  185.       }
  186.  
  187.       this.progress = var1;
  188.       ((Component)this).repaint();
  189.    }
  190.  
  191.    public void setValue(int var1) {
  192.       this.updateProgress(var1);
  193.    }
  194.  
  195.    public int getValue() {
  196.       return this.progress;
  197.    }
  198.  
  199.    public void update(Graphics var1) {
  200.       this.paint(var1);
  201.    }
  202.  
  203.    public void paint(Graphics var1) {
  204.       Rectangle var2 = ((Component)this).bounds();
  205.       Color var3 = var1.getColor();
  206.       if (this.color1 != null) {
  207.          var1.clipRect(0, 0, var2.width, var2.height);
  208.          var1.setColor(this.color1);
  209.          var1.drawLine(1 + this.indent, this.indent, var2.width - 3 - this.indent, this.indent);
  210.          var1.setColor(this.color2);
  211.          var1.drawLine(1 + this.indent, var2.height - 1 - this.indent, var2.width - 3 - this.indent, var2.height - 1 - this.indent);
  212.          var1.setColor(this.color1);
  213.          var1.drawLine(this.indent, this.indent, this.indent, var2.height - 1 - this.indent);
  214.          var1.setColor(this.color2);
  215.          var1.drawLine(var2.width - 2 - this.indent, this.indent, var2.width - 2 - this.indent, var2.height - 1 - this.indent);
  216.          var1.clipRect(1 + this.indent, 1 + this.indent, var2.width - 3 - this.indent, var2.height - 2 - this.indent);
  217.          this.yTemp = 1 + this.indent;
  218.       } else {
  219.          var1.setColor(((Component)this).getBackground());
  220.          var1.drawRect(this.indent, this.indent, var2.width - 2 - this.indent, var2.height - 1 - this.indent);
  221.          var1.clipRect(2, 1, var2.width - 3, var2.height - 2);
  222.          this.yTemp = 1;
  223.       }
  224.  
  225.       var1.setColor(this.progressColor);
  226.       if (this.bDrawBoxes) {
  227.          int var4 = this.boxWidth + this.gapWidth;
  228.          int var5 = this.boxWidth * 100 / var2.width;
  229.          int var6 = 0;
  230.  
  231.          for(int var7 = 0; var5 < this.progress; var5 = (var6 + this.boxWidth) * 100 / var2.width) {
  232.             var1.setColor(this.progressColor);
  233.             var1.fillRect(var4 * var7, 1, this.boxWidth, var2.height - 2);
  234.             var1.setColor(((Component)this).getBackground());
  235.             var1.fillRect(var4 * var7 + this.boxWidth, 1, this.gapWidth, var2.height - 2);
  236.             ++var7;
  237.             var6 = var4 * var7;
  238.          }
  239.  
  240.          var1.setColor(((Component)this).getBackground());
  241.          var1.fillRect(var6 + 1, 1, var2.width - var6 - 1, var2.height - 1);
  242.       } else {
  243.          var1.fillRect(1, 1, var2.width * this.progress / 100, var2.height - 1);
  244.          var1.setColor(((Component)this).getBackground());
  245.          var1.fillRect(1 + var2.width * this.progress / 100, 1, var2.width - var2.width * this.progress / 100, var2.height - 1);
  246.       }
  247.  
  248.       if (this.bShowProgress) {
  249.          this.field_0 = ((Component)this).getFontMetrics(((Component)this).getFont());
  250.          this.yTemp = (var2.height + this.field_0.getAscent()) / 2 - 2;
  251.          var1.setColor(this.textColor);
  252.          String var8 = Integer.toString(this.progress) + "%";
  253.          this.xTemp = (var2.width - this.field_0.stringWidth(var8)) / 2;
  254.          switch (this.align) {
  255.             case 0:
  256.                if (this.type == 3) {
  257.                   var1.drawString(var8, 4, this.yTemp);
  258.                } else {
  259.                   var1.drawString(var8, 8, this.yTemp);
  260.                }
  261.                break;
  262.             case 1:
  263.                this.xTemp = (var2.width - this.field_0.stringWidth(var8)) / 2;
  264.                if (this.type == 3) {
  265.                   var1.drawString(var8, this.xTemp, this.yTemp);
  266.                } else {
  267.                   var1.drawString(var8, this.xTemp, this.yTemp);
  268.                }
  269.                break;
  270.             case 2:
  271.                this.xTemp = var2.width - this.field_0.stringWidth(var8);
  272.                if (this.type == 3) {
  273.                   var1.drawString(var8, this.xTemp - 6, this.yTemp);
  274.                } else {
  275.                   var1.drawString(var8, this.xTemp - 10, this.yTemp);
  276.                }
  277.          }
  278.       }
  279.  
  280.       var1.setColor(var3);
  281.    }
  282.  
  283.    public Dimension preferredSize() {
  284.       Dimension var1 = ((Component)this).size();
  285.       Dimension var2 = this.minimumSize();
  286.       return new Dimension(Math.max(var1.width, var2.width), Math.max(var1.height, var2.height));
  287.    }
  288.  
  289.    public Dimension minimumSize() {
  290.       this.field_0 = ((Component)this).getFontMetrics(((Component)this).getFont());
  291.       return new Dimension(50, this.field_0.getHeight() + 4);
  292.    }
  293. }
  294.